<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<meta name="renderer" content="webkit|ie-comp|ie-stand" />
	<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
	<title>教师/助教-课堂-共享</title>
	<link rel="stylesheet" type="text/css" href="<c:url value='/css/classroomShare.css'/>" />
	<link rel="stylesheet" type="text/css" href="<c:url value='/css/common-main.css'/>"/>
	<%@ include file="/common/commonLib.jsp"%>

</head>
<body>
	
	<div class="container-fluid main">
		<%@include file="/common/header.jsp"%>
		<%@include file="common/classroomHeader.jsp"%>
		<div class="row">
			<div class="col-md-1"></div>
			<div class="col-xs-12 col-sm-12 col-md-10">
				<%@include file="common/classroomNav.jsp"%>
				<!-- 共享列表 -->
				<div id="share-list" >
					<table class="table table-hover">
						<thead>
							<tr>
								<th>
									<select class="form-control" id="selectShareType" onchange="searchType()">
										<option selected = "selected" value="ALL">全部</option>
										<option value="TESTINLESSON">当堂测试</option>
										<option value="HOMEWORK">课后作业</option>
										<option value="LABTEST">实验任务</option>
									</select>
								</th>
								<th>任务名</th>
								<th>共享者</th>
								<th>共享时间</th>
							</tr>
						</thead>
						<tbody id="shareList">
							<tr>
								<td>实验课题目</td>
								<td>任务名</td>
								<td>共享者</td>
								<td>共享时间</td>
							</tr>
						</tbody>
					</table>
				</div>
			
				<!-- 共享任务详细信息 -->
				<div id="share-detail">
					<div class="col-md-12">
						<!-- 任务名称   && 任务类型 -->
						<div class="">
							<label>任务名称</label>
							<span id="title"></span>
						</div>
					</div>
					
					<!-- 任务答案 -->
					<div class="col-md-12">
						<label>任务答案</label>
						<div id="answer" class="task-answer-stu-submit"></div>
					</div>
					<!-- 答案附件 -->
					<div class="col-md-12">
						<label>任务答案附件</label>
						<div class="lesson-share-file-list">
							<ul id="answerAttachList">
								
							</ul>
						</div>
						
					</div>
					
					<!-- 评语 -->
					<div class="col-md-12">
						<label>评语</label>
						<div class="teacher-comment" id="comment">
							
						</div>
					</div>
					<div class="col-md-12" style="text-align:center;">
						<input type="button" class="btn btn-primary" id="return" value="返回" >
					</div>
				</div>
			</div>
			<div class="col-md-1"></div>
		</div>
	</div>
	<%@include file="/common/footer.jsp"%>
</body>
<script>
var data=${data};
$(document).ready(function(){
	if (data.status != "success"){
		layer.alert(data.message);
		return;
	}
	$("#classroom-href-share").css("color","#00b43c");
	initLesson(data.data.lesson.id);//初始化课堂信息
	initShareList(data.data.list);
	showList();
	changeLessonUrl(data.data.lesson.id);//初始化导航链接
	$("#return").click(showList);
});

var initShareList= function(list){
	var shareList = $("#shareList");
	shareList.empty();
	if(list.length <= 0){
		var s="<tr><td colspan=\"4\">暂无共享</td></tr>";
		shareList.append(s);
	}
	for(var i=0;i<list.length;i++){
		var item=list[i];
		var s="<tr onclick=\"clickTr("+item.submitId+")\">";
		s+="<td title=\""+getType(item.type)+"\">"+getType(item.type)+"</td>";
		s+="<td title=\""+item.title+"\">"+item.title+"</td>";
		s+="<td title=\""+item.shareName+"\">"+item.shareName+"</td>";
		s+="<td title=\""+item.shareDate+"\">"+item.shareDate+"</td>";
		s+="</tr>";
		shareList.append(s);
	};
}
var getType = function(type) {
	if(type=="ASKINLESSON"){
		return "课堂提问";
	}else if(type=="TESTINLESSON"){
		return "当堂测试";
	}else if(type=="HOMEWORK"){
		return "课后作业";
	}else if(type=="LABTEST"){
		return "实验任务";
	}else{
		return "其他";
	}
}
var clickTr= function(id){
	showDetail();
	$.get(CONTEXT_PATH+"shareTaskView/ajaxDetail?id="+id, function(data) {
		if(data.status=="success"){
			initShareDetail(data.data.view);
			showDetail();
		}else{
			layer.alert(data.message);
		}
	});
}
var initShareDetail = function(view){
	$("#title").text(view.title);
	$("#answer").html(view.answer);
	var files=$("#answerAttachList");
	files.empty();
	for(var i=0;i<view.answerAttachment.files.length;i++){
		var item=view.answerAttachment.files[i];
		var s="<li>";
		s+="<span class=\"file-name-date\"  title=\""+item.name+"\">"+item.name+"</span>";
		s+="<span class=\"file-upload-stu\"><a href=\"<c:url value='/resource/download/"+item.url+"'/>\">下载</a></span>";
		s+="</li>";
		files.append(s);
	}
	if(view.evaluate == null || view.evaluate.trim() == "<p><br></p>"){
		$("#comment").html("<p>暂无评语</p>");
	}else{
		$("#comment").html(view.evaluate);
	}	
}
var showList=function(){
	$("#share-detail").hide();
	$("#share-list").show();
}

var showDetail = function(){
	$("#share-detail").show();
	$("#share-list").hide();
}

var searchType = function(){
	
	var shareType=$("#selectShareType  option:selected").val();
	var json={
			lessonId:data.data.lesson.id,
			type:shareType
	};
	if(shareType=="ALL"){
		delete json.type;
	}
	getShareList(json);
}

var getShareList = function(json){

	$.get(CONTEXT_PATH+"shareTaskView/ajaxTListData", {
		data: JSON.stringify(json)
	}, function(data) {
		if(data.status == "success"){
			initShareList(data.data.list);
		}else{
			layer.alert(data.message);
		}
	});
}
</script>
</html>